<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>订单信息</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@include file="common.jsp"%>
<style type="text/css">
	.queryBtn{
		margin-left:10px;
		width:50px;
		height:30px;
		font-size:16px;
		padding:0;
	}
</style>
</head>
<body style="margin-top:-10px;">
	<div style="margin-top:20px;">
	<table>
		<tr>
			<td>报单编码：</td>
			<td><input id="declarationId" name="declarationId" type="text" style="height:30px;" /></td>
			<td><button class="btn btn-primary btn-lg queryBtn" data-toggle="modal" data-target="#addDeclarationBox" onclick="queryOrder()">查询</button></td>
			<td><button class="btn btn-primary btn-lg queryBtn" data-toggle="modal" data-target="#addDeclarationBox" onclick="auditOrder()">审核</button></td>
			<td><button class="btn btn-primary btn-lg queryBtn" data-toggle="modal" data-target="#addDeclarationBox" onclick="auditFileOrder()">驳回</button></td>
		</tr>
	</table>
	</div>
	<div>
		<table id="orderTable" class="text-nowrap"></table>
	</div>
</body>
<script type="text/javascript">
//重载表格
$(function(){
	//加载表格
	$("#orderTable").bootstrapTable({
		url: "${pageContext.request.contextPath}/order/findOrder.do",
		method: "post",
		cache: false,
		dataType: "json",
		contentType: "application/x-www-form-urlencoded",
		toolbar: "#toolbar",
		classes: "table table-hover table-striped",
		height:450,
		pagination: true,
		sidePagination: 'server',
		search: false,
		smartDisplay:false,
		sortOrder: "desc",
		searchText: "",
		showRefresh: false,
		showToggle: false,
		singleSelect: true,
		showPaginationSwitch: false,
		pageNumber: 1,
		pageSize: 5,
		pageList: [5, 10, 20, 40],
		clickToSelect: true,
		onCheck: function (row) {
		},
		queryParamsType: "undefined",
		queryParams: function (params) {
			var params = {
				pageNum: params.pageNumber,
				pageSize: params.pageSize,
				sortBy: params.sortOrder,
			}
			return params;
		},
		columns: [
			{
				field:	"",
				title:	"",
				checkbox: true
			},	{
				field: "declarationId",
				title: "报单编码"
			}, {
				field: "userName",
				title: "用户名称"
			}, {
				field: "userTypeName",
				title: "用户类别"
			}, {
				field: "bankName",
				title: "银行名称"
			}, {
				field: "bankTypeName",
				title: "产品名称"
			}, {
				field: "orderStatus",
				title: "订单状态",
				formatter: formatOrderStatus
			}, {
				field: "orderType",
				title: "订单类型",
				formatter: formatOrderType
			}, {
				field: "exchangeMoney",
				title: "金额"
			}, {
				field: "exchangeRate",
				title: "汇率信息"
			}, {
				field: "exchangeIntegral",
				title: "兑换积分"
			}, {
				field: "createTime",
				title: "创建时间",
				formatter: formatTime
			}
			
		],
		responseHandler: function (data) {//onLoad前处理数据源
			return data;
		},
		onLoadSuccess: function (data) {	//成功时执行
		},
		onLoadError: function (data) {	//失败时执行
			return;
		}
	});
	//重载表格
	$(window).resize(function () {
		$('#orderTable').bootstrapTable('resetView');
	});
})
//格式化订单状态
function formatOrderStatus(value, row, index){
	if(value == null) {
		return '';
	}
	if(value == 0){
		return "未审核";
	}
	if(value == 1){
		return "已审核";
	}
	if(value == 2){
		return "驳回";
	}

}
//格式化订单类型
function formatOrderType(value, row, index){
	if(value == null) {
		return '';
	}
	if(value == 1){
		return "积分兑换";
	}
	if(value == 2){
		return "提现";
	}
	if(value == 3){
		return "充值";
	}
	if(value == 4){
		return "积分返利";
	}
	if(value == 5){
		return "充值返利";
	}
}
//根据报单编码查询
function queryOrder(){
	var declarationId = $('#declarationId').val();
	$('#orderTable').bootstrapTable('refresh',{query: {declarationId: declarationId}});
}
//审核
function auditOrder(){
	var datas = $('#orderTable').bootstrapTable('getSelections');
	if(datas.length <= 0){
        alert('请选择数据！');
        return;
    }
	var data = datas[0];
	if(data.status == 1){
		alert("请选择未审核的数据");
		return;
	}
	if(confirm("确认审核 ？")){
		$.ajax({
			url:"${pageContext.request.contextPath}/weixin/wxPayment.do",
			data: {
				money: data.exchangeMoney,
				userCode: data.userCode,
				productNo: data.orderNo
			},
			type:"post",
			dataType:"json",
			processData: true,
			success:function(data){
				alert("审核成功！");
				//刷新表格数据
				$('#orderTable').bootstrapTable('refresh');
			}
		})
	}
}
//驳回
function auditFileOrder(){
	var datas = $('#orderTable').bootstrapTable('getSelections');
	if(datas.length <= 0){
        alert('请选择数据！');
        return;
    }
	var data = datas[0];
	if(data.status == 1){
		alert("请选择未审核的数据");
		return;
	}
	if(confirm("确认驳回 ？")){
		$.ajax({
			url:"${pageContext.request.contextPath}/order/auditFileOrder.do",
			data: {
				money: data.exchangeMoney,
				userCode: data.userCode,
				orderNo: data.orderNo
			},
			type:"post",
			dataType:"json",
			processData: true,
			success:function(data){
				alert("订单驳回！")
				//刷新表格数据
				$('#orderTable').bootstrapTable('refresh');
			}
		})
	}
}
</script>
</html>